'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE ,UUID,TEXT,FLOAT} = app.Sequelize;
  var moment = require('moment');

  const fd_test = app.model.define('fd_test', {
    id: { type: UUID, primaryKey: true},
    order:STRING(2),//序号
    name:STRING(10),//类别名称，
    is_parent:{type:STRING(1),defaultValue:'1'},//是否是大类，1是，0 否
    parent:STRING(50),//所属大类
    price:FLOAT(4,2),//单价
    pic:STRING(255),//示意图
    deleted:{type:STRING(1),defaultValue:'0'} ,//0:可用 ,1:不可用
    created_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('created_at')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
    updated_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('updated_at')).format('YYYY-MM-DD HH:mm:ss');
      }
    }
  },{freezeTableName: true,timestamps: true});

  fd_test.associate = function() {
    app.model.FdTest.belongsTo(app.model.FdText, { foreignKey: 'text_id', targetKey: 'id' });
  }

  return fd_test;
};
